
    <main class="lyear-layout-content">

        <div class="container-fluid p-t-15">

            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-toolbar d-flex flex-column flex-md-row">
                            <form class="search-bar" method="get" action="{:url('admin/order/returnorder')}"
                                role="form">
                                <input type="hidden" name="search_field" id="search-field" value="code" />
                                <div class="input-group ml-md-auto">
                                    <div class="input-group-prepend">
                                        <button class="btn btn-default dropdown-toggle" type="button"
                                            aria-haspopup="true" aria-expanded="false" id="search-btn">订单单号</button>
                                        <!-- <div class="dropdown-menu">
                                            <a class="dropdown-item" data-field="code">订单单号</a>
                                        </div> -->
                                    </div>
                                    <input type="text" class="form-control" name="keyword" placeholder="请输入相应搜索订单号">
                                </div>
                            </form>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th>退货申请人</th>
                                            <th>订单单号</th>
                                            <th>下单时间</th>
                                            <th>退货理由</th>
                                            <th>退货状态</th>
                                            <th>退货审核</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {foreach $returnOrderList as $item}
                                        <tr>
                                            <td>{$item['user']['nickname']}</td>
                                            <td>{$item['code']}</td>
                                            <td>{$item['createtime']}</td>
                                            <td>{$item['content']}</td>
                                            {if condition="$item['status']==-2"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-info">申请退货中</span>
                                            </td>
                                            {elseif condition="$item['status']==-1"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-success">已退货</span>
                                            </td>
                                            {else /}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-danger">拒绝退货</span>
                                            </td>
                                            {/if}
                                            {if condition="$item['status']==-2"}
                                            <td>
                                                <div class="btn-group">
                                                    <a type="button" class="btn btn-sm btn-info ajax-agree" title=""
                                                        data-id="{$item.id}">同意退货</a>
                                                </div>
                                            </td>
                                            {elseif condition="$item['status']==-1"}
                                            <td>
                                                <div class="btn-group">
                                                    <a type="button" class="btn btn-sm btn-success " title=""
                                                        data-id="{$item.id}">已确认</a>
                                                </div>
                                            </td>
                                            {else /}
                                            <td>
                                                <div class="btn-group">
                                                    <a type="button" class="btn btn-sm btn-danger ajax-agree" title=""
                                                        data-id="{$item.id}">再次退货</a>
                                                </div>
                                            </td>
                                            {/if}
                                        </tr>
                                        {/foreach}
                                    </tbody>
                                </table>
                            </div>
                            {$returnOrderList->render()}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <script>
        layui.use(['layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer

        //搜索框的点击
        // $('.search-bar .dropdown-menu a').click(function () {
        //     var field = $(this).data('field') || '';
        //     $('#search-field').val(field);
        //     $('#search-btn').html($(this).text());
        // });

        $('.ajax-agree').click(function () {
        let id = $(this).data('id')

        layer.confirm('确认同意退货？', { icon: 3, title: '提示' }, function (index) {
                //发起请求
                $.ajax({
                    type: 'post',
                    url: `{:url('admin/order/returnorder')}`,
                    data: {
                        id,
                        action: 'agreeOrder'
                    },
                    dataType: 'json',
                    success: function (res) {
                        if (res.code === 1) {
                            layer.msg('退货成功', { icon: 1 }, function (index) {
                                location.href = res.url
                            })
                        } else {
                            layer.msg(res.msg, { icon: 5 })
                        }
                    }
                })
                layer.close(index)
            })
        })
    })
    </script>
